/** 获取设备信息 */
class DeviceInfoUtils {

	/** 
	 * 获取安卓设备标识
	 * @return {Object} 返回结果：{ OAID: "", IMEI: "" }
	 * */
	static getAndroidInfo() {
		const result = { OAID: "", IMEI: "" };
		return new Promise((resolve, reject) => {
			plus.device.getInfo({
				success(res) { result.IMEI = res.imei; },
				complete() {
					if (result.IMEI) resolve(result);
					else {
						plus.device.getOAID({
							success(res) { result.OAID = res.oaid },
							complete(e) { resolve(result) }
						});
					}
				}
			})
		})
	}

	/** 
	 * 获取IOS的IDFA
	 * @return {String} IDFA结果
	 * */
	static getIosIDFA() {
		/*
			需要开启IOS广告标识
				manifest.json文件中ios配置以下内容
				"frameworks" : [ "AdSupport.framework" ],
				"idfa" : "true"
		*/
		return new Promise((resolve, reject) => {
			let result = "";
			plus.device.getInfo({
				success: (e) => result = e.idfa,
				complete: () => resolve(result)
			});
		})
	}
}

export { DeviceInfoUtils }